package com.kidfruit.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * Created by kidfruit on 2016/12/2 002.
 */

@Aspect
public class SleepHelper {

    @Pointcut("execution(* com.kidfruit.aop..*.sleep(..))")
    public void sleepPoint() {
    }

    @Before("sleepPoint()")
    public void beforeSleep() {
        System.out.println("before sleep");
    }

    @After("sleepPoint()")
    public void afterSleep() {
        System.out.println("after sleep");
    }

    @Pointcut("execution(* com.kidfruit.aop..*.calc(..))")
    public void calcPoint() {
    }

    @AfterReturning(pointcut = "calcPoint()", returning = "returnValue")
    public void afterReturningCalc(Object returnValue) {
        System.out.println("calc = " + returnValue);
    }

    @Around("calcPoint()")
    public Object arroundCalc(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("before calc");
        Object result = pjp.proceed();
        System.out.println("after calc");

        return result;
    }
}
